import { Injectable } from '@angular/core';
import { Subject, Observable } from 'rxjs';

@Injectable({
  providedIn: 'root'
})
export class SharedService {
  private msg$ = new Subject<any>();
  constructor() { }

  //发送消息
  sentMessage = (msg: string) => {
    this.msg$.next(msg);
  }

  //清除消息
  clearMessage = () => {
    this.msg$.next(null);
  }

  //获取消息
  getMessage = (): Observable<any> => {
    return this.msg$.asObservable();
  }
}
